home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / tp / custom / btntest.pas next >
Pascal/Delphi Source File  |  1991-07-24  |  5KB  |  202 lines

  1. {************************************************************************
  2. *
  3. *    Custom Control Test Program With Bitmap Buttons
  4. *
  5. *    WRITTEN BY:        Shawn Aubrey Baker (aka sab)
  6. *
  7. *    COMPUSERVE ID:    76450,22
  8. *
  9. *    CREDITS:            This code is largely copied from the test program
  10. *                        supplied by Robert Norton with his bitmap button unit.
  11. *
  12. *    USE:                As you wish. Please send any comments and/or bug fixes
  13. *                        via mail to the above ID. IF IT DIES IT'S YOUR PROBLEM.
  14. *
  15. *    NOTES:            This file uses tabs = 3
  16. *
  17. *                        This program will run in a TWindow by default. If you
  18. *                        set the conditional compilation name DIALOG then it
  19. *                        will run in a TDlgWindow and use the resource defined
  20. *                        in BTNTEST.RES.
  21. *
  22. *    THE END.
  23. *
  24. ************************************************************************}
  25.  
  26. program ButtonTest;
  27.  
  28. uses    WinTypes,WinProcs,WObjects,Strings,Custom;
  29.  
  30. {$R btntest.res}
  31.  
  32. const
  33.  
  34.         id_Button1=101;
  35.         id_Button2=102;
  36.         id_Button3=103;
  37.         id_Button4=104;
  38.         id_Button5=105;
  39.         id_Button6=106;
  40.  
  41. type
  42.  
  43.         PBitWindow=^TBitWindow;
  44. {$IFDEF DIALOG}
  45.         TBitWindow=object(TDlgWindow)
  46. {$ELSE}
  47.         TBitWindow=object(TWindow)
  48. {$ENDIF}
  49.             PB1,PB2,PB3,PB4:PBitButton;        { bit buttons        }
  50.             B1,B2:PButton;                            { normal buttons    }
  51.  
  52.             constructor    Init;
  53.             destructor    Done; virtual;
  54.  
  55.             procedure    DoYes(var Msg:TMessage);
  56.                                                 virtual id_First + id_Button1;
  57.             procedure    DoNo(var Msg:TMessage);
  58.                                                 virtual id_First + id_Button2;
  59.             procedure    DoOk(var Msg:TMessage);
  60.                                                 virtual id_First + id_Button3;
  61.             procedure    DoCancel(var Msg:TMessage);
  62.                                                 virtual id_First + id_Button4;
  63.             procedure    DoHi(var Msg:TMessage);
  64.                                                 virtual id_First + id_Button5;
  65.             procedure    DoBye(var Msg:TMessage);
  66.                                                 virtual id_First + id_Button6;
  67.             end;
  68.  
  69.         PBtnApp=^TBtnApp;
  70.         TBtnApp=object(TApplication)
  71.             constructor    Init(AName: PChar);
  72.             destructor    Done; virtual;
  73.  
  74.             procedure    InitMainWindow; virtual;
  75.             end;
  76.  
  77. {------------------------------------------------------------------------
  78. -------------------------------------------------------------------------
  79. ----                                        TBitApp Object                                ----
  80. -------------------------------------------------------------------------
  81. ------------------------------------------------------------------------}
  82.  
  83. constructor TBtnApp.Init(AName:PChar);
  84. begin
  85. TApplication.Init(AName);
  86. end;
  87.  
  88. destructor TBtnApp.Done;
  89. begin
  90. TApplication.Done;
  91. end;
  92.  
  93. procedure TBtnApp.InitMainWindow;
  94. begin
  95. MainWindow:=New(PBitWindow,Init);
  96. end;
  97.  
  98. {------------------------------------------------------------------------
  99. -------------------------------------------------------------------------
  100. ----                                    TBitWindow Object                                ----
  101. -------------------------------------------------------------------------
  102. ------------------------------------------------------------------------}
  103.  
  104. constructor TBitWindow.Init;
  105. begin
  106.  
  107. {$IFDEF DIALOG}
  108.  
  109. TDlgWindow.Init(nil,'BIT_BUTTON_DIALOG');
  110.  
  111. PB1:=New(PBitButton,InitResource(@Self,id_Button1,
  112.             PChar(1006),PChar(5006),PChar(3006)));
  113. PB2:=New(PBitButton,InitResource(@Self,id_Button2,
  114.             PChar(1007),PChar(5007),PChar(3007)));
  115. PB3:=New(PBitButton,InitResource(@Self,id_Button3,
  116.             PChar(1001),PChar(5001),PChar(3001)));
  117. PB4:=New(PBitButton,InitResource(@Self,id_button4,
  118.             PChar(1002),PChar(5002),PChar(3002)));
  119. B1:=New(PButton,InitResource(@Self,id_Button5));
  120. B2:=New(PButton,InitResource(@Self,id_Button6));
  121.  
  122. {$ELSE}
  123.  
  124. TWindow.Init(nil,'Button Test');
  125.  
  126. PB1:=New(PBitButton,Init(@Self,id_Button1,10,10,
  127.             PChar(1006),PChar(5006),PChar(3006),false));
  128. PB2:=New(PBitButton,Init(@Self,id_Button2,150,10,
  129.             PChar(1007),PChar(5007),PChar(3007),false));
  130. PB3:=New(PBitButton,Init(@Self,id_Button3,10,70,
  131.             PChar(1001),PChar(5001),PChar(3001),true));
  132. PB4:=New(PBitButton,Init(@Self,id_Button4,150,70,
  133.             PChar(1002),PChar(5002),PChar(3002),false));
  134. B1:=New(PButton, Init(@Self,id_Button5,'Hi',300,10,60,30,false));
  135. B2:=New(PButton, Init(@Self,id_Button6,'Bye',300,70,60,30,false));
  136. EnableKBHandler;
  137.  
  138. {$ENDIF}
  139.  
  140. end;
  141.  
  142. destructor TBitWindow.Done;
  143. begin
  144. Dispose(PB1,Done);
  145. Dispose(PB2,Done);
  146. Dispose(PB3,Done);
  147. Dispose(PB4,Done);
  148. Dispose(B1,Done);
  149. Dispose(B2,Done);
  150.  
  151. {$IFDEF DIALOG}
  152. TDlgWindow.Done;
  153. {$ELSE}
  154. TWindow.Done;
  155. {$ENDIF}
  156.  
  157. end;
  158.  
  159. procedure TBitWindow.DoYes(var Msg:TMessage);
  160. begin
  161. MessageBox(hWindow,'Yes','You pushed:',mb_Ok);
  162. end;
  163.  
  164. procedure TBitWindow.DoNo(var Msg:TMessage);
  165. begin
  166. MessageBox(hWindow,'No','You pushed:',mb_Ok);
  167. end;
  168.  
  169. procedure TBitWindow.DoOk(var Msg:TMessage);
  170. begin
  171. MessageBox(hWindow,'OK','You pushed:',mb_Ok);
  172. end;
  173.  
  174. procedure TBitWindow.DoCancel(var Msg:TMessage);
  175. begin
  176. MessageBox(hWindow,'Cancel','You pushed:',mb_Ok);
  177. end;
  178.  
  179. procedure TBitWindow.DoHi(var Msg:TMessage);
  180. begin
  181. MessageBox(hWindow,'Hi','You pushed:',mb_Ok);
  182. end;
  183.  
  184. procedure TBitWindow.DoBye(var Msg:TMessage);
  185. begin
  186. MessageBox(hWindow,'Bye','You pushed:',mb_Ok);
  187. end;
  188.  
  189. {------------------------------------------------------------------------
  190. -------------------------------------------------------------------------
  191. ----                                        Mainline                                        ----
  192. -------------------------------------------------------------------------
  193. ------------------------------------------------------------------------}
  194.  
  195. var    BtnApp:TBtnApp;
  196.  
  197. begin
  198. BtnApp.Init('BitButton Test');
  199. BtnApp.Run;
  200. BtnApp.Done;
  201. end.
  202.